package com.javaweb.controller;


import com.javaweb.controller.common.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/10/22 17:01
 */

@Controller
@Slf4j
@RequestMapping("/error")
public class ErrorController {

    @PostMapping("/400")
    @ResponseBody
    public ResponseResult<String> error400(HttpServletRequest req) {
        log.info("errorMsg: {}",req.getAttribute("errorMsg")) ;
        return ResponseResult.error(HttpStatus.BAD_REQUEST,
                req.getAttribute("errorMsg").toString());
    }


    @PostMapping("/401")
    @ResponseBody
    public ResponseResult<String> error401(HttpServletRequest req) {
        log.info("errorMsg: {}",req.getAttribute("errorMsg")) ;

        return ResponseResult.error(HttpStatus.UNAUTHORIZED, req.getAttribute("errorMsg").toString());
    }


}
